package merge;

public class Solution {
    public void merge(int[] A, int m, int[] B, int n) {
        int index = m + n -1;
        int i = m-1,j = n-1;
        while (index>=0) {
            int cur;
            if( i < 0) {
                cur = B[j];
                j--;
            } else if ( j < 0 ) {
                cur = A[i];
                i--;
            } else if ( A[i] > B[j] )  {
                cur = A[i];
                i--;
            } else {
                cur = B[j];
                j--;
            }
            A[index--] = cur;
        }
    }
}
